package com.sgb.kjwl.view.ui.activity.self;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;
import android.view.View;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityMessageBinding;
import com.sgb.kjwl.di.self.DaggerSelfComponent;
import com.sgb.kjwl.di.self.SelfModule;
import com.sgb.kjwl.model.entity.user.MessageEntity;
import com.sgb.kjwl.view.ui.adapter.self.MessageAdapter;
import com.sgb.kjwl.viewmodel.self.MessageModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.xrecyclerview.XRecyclerView;

import java.util.List;

import javax.inject.Inject;

/**
 *
 */
public class MessageActivity extends AppActivity {

    @Inject
    MessageModel viewModel;
    ActivityMessageBinding binding;
    private MessageAdapter messageAdapter;

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerSelfComponent.builder().appComponent(appComponent)
                .selfModule(new SelfModule(this)).build().inject(this);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(MessageActivity.this, R.layout.activity_message);
        binding.include.titleView.setText("我的消息");
        binding.include.ivBack.setOnClickListener(this);
        binding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        messageAdapter = new MessageAdapter(this, null);
        binding.recyclerView.setAdapter(messageAdapter);
        binding.recyclerView.setLoadingMoreEnabled(false);
        binding.recyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                viewModel.getMessageList();

            }

            @Override
            public void onLoadMore() {

            }
        });

    }

    @Override
    protected void init() {
        viewModel.getMessageList();

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;

        }
    }

    public void showMessage(List<MessageEntity> list) {
        binding.recyclerView.refreshComplete();
        messageAdapter.setDatas(list);
    }
}
